﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmSearch
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtTen As System.Windows.Forms.TextBox
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents MatinhDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TentinhDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents GhichuDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MamienDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents txtMa As System.Windows.Forms.TextBox
    Friend WithEvents btnTimKiem As System.Windows.Forms.Button
    Friend WithEvents optHangHoa As System.Windows.Forms.RadioButton
    Friend WithEvents optKhachHang As System.Windows.Forms.RadioButton
    Friend WithEvents DataSetSearch As MEKONG.DataSetSearch
    Friend WithEvents MaDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TenDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataSetSearchBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataGridViewTextBoxColumn1 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataGridViewTextBoxColumn2 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmSearch))
        Me.txtTen = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.txtMa = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.btnTimKiem = New System.Windows.Forms.Button
        Me.optHangHoa = New System.Windows.Forms.RadioButton
        Me.optKhachHang = New System.Windows.Forms.RadioButton
        Me.DataSetSearch = New MEKONG.DataSetSearch
        Me.DataSetSearchBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataGridViewTextBoxColumn1 = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.DataGridViewTextBoxColumn2 = New System.Windows.Forms.DataGridViewTextBoxColumn
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetSearchBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'txtTen
        '
        Me.txtTen.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTen.Location = New System.Drawing.Point(50, 59)
        Me.txtTen.MaxLength = 50
        Me.txtTen.Name = "txtTen"
        Me.txtTen.Size = New System.Drawing.Size(265, 22)
        Me.txtTen.TabIndex = 2
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(3, 60)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(41, 16)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Tên"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(56, 4)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(203, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "TÌM KIẾM NHANH"
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.DataGridViewTextBoxColumn1, Me.DataGridViewTextBoxColumn2})
        Me.DataGridView1.DataMember = "tbl_search"
        Me.DataGridView1.DataSource = Me.DataSetSearchBindingSource
        Me.DataGridView1.Location = New System.Drawing.Point(6, 92)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.Size = New System.Drawing.Size(419, 139)
        Me.DataGridView1.TabIndex = 40
        '
        'txtMa
        '
        Me.txtMa.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtMa.Location = New System.Drawing.Point(50, 31)
        Me.txtMa.MaxLength = 50
        Me.txtMa.Name = "txtMa"
        Me.txtMa.Size = New System.Drawing.Size(175, 22)
        Me.txtMa.TabIndex = 41
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(3, 31)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(41, 16)
        Me.Label3.TabIndex = 42
        Me.Label3.Text = "Mã"
        '
        'btnTimKiem
        '
        Me.btnTimKiem.Image = Global.MEKONG.My.Resources.Resources.tim
        Me.btnTimKiem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnTimKiem.Location = New System.Drawing.Point(321, 57)
        Me.btnTimKiem.Name = "btnTimKiem"
        Me.btnTimKiem.Size = New System.Drawing.Size(105, 26)
        Me.btnTimKiem.TabIndex = 61
        Me.btnTimKiem.Text = "Tìm kiếm..."
        Me.btnTimKiem.UseVisualStyleBackColor = True
        '
        'optHangHoa
        '
        Me.optHangHoa.AutoSize = True
        Me.optHangHoa.Location = New System.Drawing.Point(231, 31)
        Me.optHangHoa.Name = "optHangHoa"
        Me.optHangHoa.Size = New System.Drawing.Size(74, 17)
        Me.optHangHoa.TabIndex = 62
        Me.optHangHoa.TabStop = True
        Me.optHangHoa.Text = "Hàng Hóa"
        Me.optHangHoa.UseVisualStyleBackColor = True
        '
        'optKhachHang
        '
        Me.optKhachHang.AutoSize = True
        Me.optKhachHang.Location = New System.Drawing.Point(321, 31)
        Me.optKhachHang.Name = "optKhachHang"
        Me.optKhachHang.Size = New System.Drawing.Size(85, 17)
        Me.optKhachHang.TabIndex = 63
        Me.optKhachHang.TabStop = True
        Me.optKhachHang.Text = "Khách Hàng"
        Me.optKhachHang.UseVisualStyleBackColor = True
        '
        'DataSetSearch
        '
        Me.DataSetSearch.DataSetName = "DataSetSearch"
        Me.DataSetSearch.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'DataSetSearchBindingSource
        '
        Me.DataSetSearchBindingSource.DataSource = Me.DataSetSearch
        Me.DataSetSearchBindingSource.Position = 0
        '
        'DataGridViewTextBoxColumn1
        '
        Me.DataGridViewTextBoxColumn1.DataPropertyName = "ma"
        Me.DataGridViewTextBoxColumn1.HeaderText = "Mã "
        Me.DataGridViewTextBoxColumn1.Name = "DataGridViewTextBoxColumn1"
        Me.DataGridViewTextBoxColumn1.ReadOnly = True
        '
        'DataGridViewTextBoxColumn2
        '
        Me.DataGridViewTextBoxColumn2.DataPropertyName = "ten"
        Me.DataGridViewTextBoxColumn2.HeaderText = "Tên"
        Me.DataGridViewTextBoxColumn2.Name = "DataGridViewTextBoxColumn2"
        Me.DataGridViewTextBoxColumn2.ReadOnly = True
        Me.DataGridViewTextBoxColumn2.Width = 270
        '
        'frmSearch
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(429, 242)
        Me.Controls.Add(Me.optKhachHang)
        Me.Controls.Add(Me.optHangHoa)
        Me.Controls.Add(Me.btnTimKiem)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.txtMa)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.txtTen)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmSearch"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Tim Kiem Nhanh"
        Me.TopMost = True
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetSearchBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private data1 As DataTable
    Private da As MySqlDataAdapter
    Dim myDT As New DataTable
    Dim strError As String = ""
    Dim myform As Form
    Dim sqlQuery As String = ""

    Sub SetclearData()
        txtMa.Text = ""
        txtTen.Text = ""
    End Sub
    Private Sub frmSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.txtTen.Focus()
        Me.optKhachHang.Checked = True

    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        If Me.optKhachHang.Checked = True Then
            sqlQuery = "select ma_nhacungcap as ma , ten_nhacungcap as ten from tbl_khachhang "
            sqlQuery += " where ma_nhacungcap like '%" & Me.txtMa.Text & "%' and ten_nhacungcap like '%" & Me.txtTen.Text & "%'"
            Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
        ElseIf Me.optHangHoa.Checked = True Then
            sqlQuery = "select ma_hanghoa as ma , ten_bietduoc as ten from tbl_hanghoa "
            sqlQuery += " where ma_hanghoa like '%" & Me.txtMa.Text & "%' and ten_bietduoc like '%" & Me.txtTen.Text & "%'"
            Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
        Else
            Me.txtTen.Focus()

        End If

    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
        Me.txtMa.Text = Me.DataGridView1.Item(0, iRow).Value
        Me.txtTen.Text = Me.DataGridView1.Item(1, iRow).Value

    End Sub

    Private Sub optHangHoa_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optHangHoa.Click
        Me.SetclearData()
    End Sub

    Private Sub optKhachHang_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optHangHoa.Click
        Me.SetclearData()
    End Sub
End Class


